package com.zm.se.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.util.Random;
@Component
public class EmailSend {

    //管理员注册授权码接收方

    //发送方
    private String sender="2924478416@qq.com";

    //生成验证码
    //共6为，数字加字符
    public String KeyCreated(){
        Random random=new Random();
        String Key= (random.nextInt(9) + 0)
                +String.valueOf((char)(random.nextInt(25) + 97))
                +(random.nextInt(9) + 0)
                + (char) (random.nextInt(25) + 97)
                +(random.nextInt(9) + 0)
                + (char) (random.nextInt(25) + 97);
        return Key;
    }

    @Autowired
    private JavaMailSender mailSender;
    //编辑短信内容并发送
    public Integer RegisterManager(String key,String PowerManEmail){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(sender);
        message.setTo(PowerManEmail);
        message.setSubject("主题：体育器材管理系统验证码");
        message.setText("您的验证码为："+key);
        mailSender.send(message);
        return 1;
    }



}
